package com.kakarote.oa.entity.PO;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.kakarote.common.field.entity.ModelFieldDetail;
import com.kakarote.core.common.enums.FieldEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 自定义字段表
 * </p>
 *
 * @author zhangzhiwei
 * @since 2020-06-22
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("wk_oa_examine_field")
@ApiModel(value = "OaExamineField对象", description = "自定义字段表")
public class OaExamineField extends ModelFieldDetail {

    private static final long serialVersionUID = 1L;


    @ApiModelProperty(value = "最后修改时间")
    @TableField(fill = FieldFill.UPDATE)
    private LocalDateTime updateTime;

    @ApiModelProperty(value = "审批ID label为10需要")
    private Long examineCategoryId;



    @ApiModelProperty(value = "创建人ID")
    @TableField(fill = FieldFill.INSERT)
    private Long createUserId;

    @ApiModelProperty(value = "修改人ID")
    @TableField(fill = FieldFill.UPDATE)
    private Long updateUserId;

    @ApiModelProperty(value = "创建时间")
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createTime;

    @ApiModelProperty(value = "是否多选 1 是 0 否")
    private Integer isMulti;


    @TableField(exist = false)
    @ApiModelProperty(value = "逻辑表单数据")
    private Map<String, Object> optionsData;


    @TableField(exist = false)
    @ApiModelProperty(value = "新字段id")
    private Long newFieldId;


    @ApiModelProperty(value = "语言包map")
    @TableField(exist = false)
    private Map<String, String> languageKeyMap;

    @ApiModelProperty(value = "权限 1不可编辑不可查看 2可查看不可编辑 3可编辑可查看")
    @TableField(exist = false)
    private Integer authLevel;

    @TableField(exist = false)
    private Integer label;

    public static OaExamineField of(Long id, String fieldName, String name, String formType, List<String> settingArr, Integer isNull, Integer isUnique, Object value, String defaultValue, Integer operating, Integer fieldType, String formPosition, Integer sorting) {
        OaExamineField record = new OaExamineField();
        record.setFieldId(id);
        record.setFieldName(fieldName);
        record.setName(name);
        record.setMaxLength(0);
        record.setIsUnique(isUnique);
        record.setIsNull(isNull);
        record.setOperating(operating);
        record.setFieldType(fieldType);
        record.setFormType(formType);
        record.setType(FieldEnum.parse(formType).getType());
        record.setSetting(Arrays.asList(settingArr.toArray()));
        record.setValue(value);
        record.setDefaultValue(defaultValue);
        record.setFormPosition(formPosition);
        record.setStylePercent(100);
        record.setSorting(sorting);
        return record;
    }
}
